package com.weilive.api.gate.json.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.weilive.api.ServerErrors;
import com.weilive.api.gate.json.protocol.CSA_DeleteVideo;
import com.weilive.api.gate.json.protocol.CSQ_DeleteVideo;
import com.weilive.api.service.UserSystem;
import com.weilive.core.protocol.json.JsonRequest;
import com.weilive.core.protocol.json.JsonRequestHandler;
import com.weilive.core.protocol.json.JsonResponse;

@Service
public class CSQ_DeleteVideo_JsonHandler extends JsonRequestHandler {

	@Autowired
	private UserSystem userSystem;

	public Class<?> getRequestType() {
		return CSQ_DeleteVideo.class;
	}

	public Class<?> getResponseType() {
		return CSA_DeleteVideo.class;
	}

	public JsonResponse handleRequest(JsonRequest request) throws Exception {
		// 判断session
		CSQ_DeleteVideo params = (CSQ_DeleteVideo) request.getData();

		long userId = userSystem.getUserId(params.getSessionId());
		if (userId == 0) {
			return createErrorResponse(ServerErrors.USER_NOT_LOGIN);
		}

		if (params.getVideoId() == null) {
			return createErrorResponse(ServerErrors.PARAM_INVALID);
		}
		userSystem.deleteVideo(userId, params.getVideoId());

		CSA_DeleteVideo response = new CSA_DeleteVideo();
		return JsonResponse.create(response);
	}

}
